<?php

/**
 * Composite menu validator
 * 
 * @author Kozlov Denis
 * @version $Id$
 * @package Kpl
 *
 */
class Menu_Validator_Composite  extends Menu_Validator_Abstract
{
	protected $_validators = Array();
	
	public function add(Menu_Validator_Abstract $validator) { 
		$this->_validators[] =  $validator;
		return $this;
	}
	
	public function remove(Menu_Validator_Abstract $validator) { 

		foreach ($this->iterator() as $key=>$component) {
			if ($validator == $component) {
				unset($this->_validators[$key]);
			}
		}

		return $this;
	}
	
	public function iterator() {
		return $this->_validators;
	}

	public function isValid($item)
	{
		foreach ($this->iterator() as $validator) {
			if (!$validator->isValid($item)) return false;
		}
		
		return true;
	}

	public function getMessages()
	{
		$result = Array();
		foreach ($this->iterator() as $validator) {
			$result = array_merge ($result,$validator->getMessages()) ;
		}
		
		return $result;
	}
	
	public function getErrors()
	{
		$result = Array();
		foreach ($this->iterator() as $validator) {
			$result = array_merge ($result,$validator->getErrors()) ;
		}
		
		return $result;
	}

}
?>